package com.pactera.integral.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.pactera.integral.common.repository.ResultMap;
import com.pactera.integral.common.web.GenericController;
import com.pactera.integral.common.web.Response;
import com.pactera.integral.entity.SummaryScore;
import com.pactera.integral.service.SummaryScoreService;

@CrossOrigin
@RestController
@EnableJpaRepositories
@RequestMapping("/wx")
public class SummaryScoreController extends GenericController {

	@Autowired
	private SummaryScoreService scoreService;

	@RequestMapping(value = "/rank", method = RequestMethod.GET)
	public Response getRank(@RequestParam String staffId, @RequestParam Integer scoreType) {
		List<ResultMap<String, Object>> list = scoreService.searchByDepartmentCode(staffId, scoreType);

		return this.normal(list);
	}
	
	@RequestMapping(value = "/rank/month", method = RequestMethod.GET)
	public Response getMonthRank(@RequestParam String staffId, @RequestParam Integer scoreType) {
		List<ResultMap<String, Object>> list = scoreService.searchMonthRankByDeparmentCode(staffId, scoreType);

		return this.normal(list);
	}

	@RequestMapping(value = "/score/add", method = RequestMethod.POST)
	public Response addScore(@RequestBody SummaryScore summaryScore) {
		
		return this.normal(scoreService.addScore(summaryScore));
	}

	@RequestMapping(value = "/user", method = RequestMethod.GET)
	public Response getUserId(@RequestParam String staffId) {
		List<ResultMap<String, Object>> list = scoreService.getUserId(staffId);
		
		return this.normal(list);
	}
	
	@RequestMapping(value = "/score/history", method = RequestMethod.GET)
	public Response getScoreHistory(@RequestParam String departmentCode) {
		List<ResultMap<String, Object>> list = scoreService.getScoreHistory(departmentCode);
		
		return this.normal(list);
	}
	
	@RequestMapping(value = "/auth", method = RequestMethod.GET)
	public Response getUserAuthority(@RequestParam String staffId) {
		List<ResultMap<String, Object>> list = scoreService.getUserAuthority(staffId);

		return this.normal(list);
	}
}
